<template>
  <div>
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      unique-opened
    >
      <div v-for="(menu, index) in menuList">
        <!-- <el-menu-item :key="index" v-if="menu.children">
          <router-link slot="title" :to="menu.name">{{ menu.meta.title }}</router-link>
        </el-menu-item> -->

        <el-submenu
          :index="`${index}`"
          :key="index"
          v-if="menu.pageType == 'entry' && menu.subPageList"
        >
          <template slot="title">
            <span>{{ menu.pageName }}</span>
          </template>
          <el-menu-item
            v-for="(menu2, index2) in menu.subPageList"
            :index="`${index}-${index2}`"
            :key="`${index}-${index2}`"
            ><router-link :to="menu2.path">{{
              menu2.pageName
            }}</router-link></el-menu-item
          >
        </el-submenu>

        <el-menu-item
          :index="`${index}`"
          :key="index"
          v-if="menu.pageType == 'entry' && !menu.subPageList"
        >
          <router-link slot="title" :to="menu.path">{{
            menu.pageName
          }}</router-link>
        </el-menu-item>
      </div>

      <!-- <el-menu-item index="2">
        <router-link slot="title" to="/News">新闻资讯</router-link>
      </el-menu-item>

      <el-menu-item index="2">
        <router-link slot="title" to="/News">新闻资讯</router-link>
      </el-menu-item>
      <el-menu-item index="3">
        <router-link slot="title" to="/Knowledge">知识管理</router-link>
      </el-menu-item>

      <el-submenu index="4">
        <template slot="title">
          <span>帮扶管理</span>
        </template>
        <el-menu-item index="2-1"
          ><router-link to="/Policy">补贴政策</router-link></el-menu-item
        >
        <el-menu-item index="2-2"
          ><router-link to="/Service">网约农服</router-link></el-menu-item
        >
      </el-submenu>
      <el-menu-item index="5">
        <router-link slot="title" to="/CreditHelp">信贷帮扶</router-link>
      </el-menu-item>
      <el-menu-item index="7">
        <router-link slot="title" to="/agricultureProducts"
          >农产品管理</router-link
        >
      </el-menu-item>
      <el-menu-item index="6">
        <router-link slot="title" to="/User">用户</router-link>
      </el-menu-item>
      <el-menu-item index="6">
        <router-link slot="title" to="/Role">角色</router-link>
      </el-menu-item>
      <el-menu-item index="7">
        <router-link slot="title" to="/Advertisement">广告位管理</router-link>
      </el-menu-item> -->
    </el-menu>
  </div>
</template>
<script>
import utils from "@/utils";
import mixins from "@/mixins";

import { queryAllPageTree } from "@/api/common";

// import { routes } from "@/router";

export default {
  data() {
    // let menus = routes[1].children;

    // menus = menus.slice(2, menus.length);
    return {
      // menus: menus,
      menuList: [],
    };
  },
  created() {
    this.queryTree();
  },
  methods: {
    async queryTree() {
      this.loading = true;
      // let { returnObj } = await queryPageTree([this.tabPosition]);
      let { returnObj } = await queryAllPageTree({
        pageType: "entry", // 菜单类型，entry：菜单，privilege：按钮，非必填，精确匹配
        systemId: "100000001", // 子系统编号，100000001：PC后台，100000002：APP   ，非必填，精确匹配
      });
      this.loading = false;
      this.menuList = returnObj;
    },
    handleOpen(key, keyPath) {
      // console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath)
    },
  },
};
</script>
<style lang="scss" scoped>
.el-menu {
  a {
    display: block;
    color: #409eff;
  }
}
</style>
